// 创建一个Watcher类，用于管理依赖与视图的更新
class Watcher {
  constructor(vm, key, cb) {
    this.vm = vm;
    this.key = key;
    this.cb = cb;
    
    Dep.target = this; // 实例挂载
    
    this.oldValue = vm[key]; // 获取数据的值
    Dep.target = null;
  }

  // 更新视图
  update() {
    const newValue = this.vm[this.key];
    if (this.oldValue === newValue) {
      return;
    }
    this.cb(newValue);
    // this.oldValue = newValue;
  }
}
